package winTime.vo;

import java.io.Serializable;

/**
 * @author fatsung<br>
 * 存放Tick K 線資料<br>
 * 內容, 開盤, 收盤, 最高, 最低, 數量, 筆數
 */
public class TickKLine implements Serializable{
	private static final long serialVersionUID = -2937136622565014315L;
	private int ctime=0;//成交時間
	private int hPrice;//最高價
	private int lPrice;//最低價
	private int oPrice;//開盤價
	private int cPrice;//收盤價
	private int cnt;//筆數
	private int price;//價格
	private long qtyPrice;//加權
	private int sQty;//總量
	/**
	 * 設定K線<br>
	 * @param ctime<br>
	 * @param price<br>
	 * @param qty<br>
	 */
	public void setData(int ctime,int price,int qty){
		if(this.ctime==0){
			this.oPrice = price;
			this.hPrice = price;
			this.lPrice = price;
			this.cPrice = price;
			this.ctime = ctime;
			this.sQty = qty;
			this.qtyPrice = qty * price;
			this.cnt = 1;
			return;
		}
		if(price>this.hPrice){
			this.hPrice = price;
		}
		if(price<this.lPrice){
			this.lPrice = price;
		}
		this.qtyPrice=this.qtyPrice+(qty*price);
		this.sQty = this.sQty + qty;
		this.cPrice = price;
		this.cnt++;
	}
	public int getCtime() {
		return ctime;
	}
	public void setCtime(int ctime) {
		this.ctime = ctime;
	}
	public int gethPrice() {
		return hPrice;
	}
	public void sethPrice(int hPrice) {
		this.hPrice = hPrice;
	}
	public int getlPrice() {
		return lPrice;
	}
	public void setlPrice(int lPrice) {
		this.lPrice = lPrice;
	}
	public int getoPrice() {
		return oPrice;
	}
	public void setoPrice(int oPrice) {
		this.oPrice = oPrice;
	}
	public int getcPrice() {
		return cPrice;
	}
	public void setcPrice(int cPrice) {
		this.cPrice = cPrice;
	}
	public int getCnt() {
		return cnt;
	}
	public void setCnt(int cnt) {
		this.cnt = cnt;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public long getQtyPrice() {
		return qtyPrice;
	}
	public void setQtyPrice(long qtyPrice) {
		this.qtyPrice = qtyPrice;
	}
	public int getsQty() {
		return sQty;
	}
	public void setsQty(int sQty) {
		this.sQty = sQty;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ctime;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TickKLine other = (TickKLine) obj;
		if (ctime != other.ctime)
			return false;
		return true;
	}
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("TickKLine [ctime=");
		builder.append(ctime);
		builder.append(", hPrice=");
		builder.append(hPrice);
		builder.append(", lPrice=");
		builder.append(lPrice);
		builder.append(", oPrice=");
		builder.append(oPrice);
		builder.append(", cPrice=");
		builder.append(cPrice);
		builder.append(", cnt=");
		builder.append(cnt);
		builder.append(", price=");
		builder.append(price);
		builder.append(", qtyPrice=");
		builder.append(qtyPrice);
		builder.append(", sQty=");
		builder.append(sQty);
		builder.append("]");
		return builder.toString();
	}

}
